﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer
{
    public partial class Referer
    {
        public static Referer FindByRefererID_IncludeDeleted(linqDatabaseDataContext db, int RefererID)
        {
            var subquery = (from u in db.Referers where u.ID == (from v in db.Referers where v.RefererID == u.RefererID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where u.RefererID == RefererID select u).SingleOrDefault());
        }

        public static Referer FindByRefererID(linqDatabaseDataContext db, int RefererID)
        {
            var subquery = (from u in db.Referers where u.ID == (from v in db.Referers where v.RefererID == u.RefererID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted && u.RefererID == RefererID select u).SingleOrDefault());
        }

        public static List<Referer> ToList_IncludeDeleted(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.Referers where u.ID == (from v in db.Referers where v.RefererID == u.RefererID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery select u).ToList());
        }

        public static List<Referer> ToList(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.Referers where u.ID == (from v in db.Referers where v.RefererID == u.RefererID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted select u).ToList());
        }

        public static List<Referer> HistoryToListByRefererID(linqDatabaseDataContext db, int RefererID)
        {
            return (from u in db.Referers where u.RefererID == RefererID orderby u.Timestamp ascending select u).ToList();
        }
    }
}
